#include "RingQueue.hpp"
#include <pthread.h>
#include "Task.hpp"
#include <time.h>
#include <unistd.h>
void* Consumer(void *Args)
{
    RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(Args);
    while(1)
    {
        Task ts = rq->pop();
        //cout<<"Producer "<<tmp<<endl;
        ts.RunTask();
        sleep(2);
    }
}

void* Producer(void *Args)
{
    RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(Args);
    while(1)
    {
        string tmp="Task num is ";
        tmp+=to_string(rand()%20+1);
        Task t(tmp);
        rq->push(t);
        cout<<"Producer "<<tmp<<endl;
        usleep(100000);
    }
}




int main()
{
    srand(time(nullptr));
    RingQueue<Task> rq;
    pthread_t c_tid;
    pthread_create(&c_tid,nullptr,Consumer,&rq);

    pthread_t p_tid;
    pthread_create(&p_tid,nullptr,Producer,&rq);

    pthread_join(c_tid,nullptr);
    pthread_join(p_tid,nullptr);

    return 0;
}